//
//  MCNNavigationBarDefine.swift
//  MCNNavigationBarDefine
//
//  Created by yhbj on 2021/9/16.
//

import UIKit

let MCNNavDefaultBackColor = UIColor.white
let MCNNavDefaultTitleColor = UIColor.black
let MCNNavDefaultLineColor = UIColor(red: 220 / 255, green: 220 / 255, blue: 220 / 255, alpha: 0.8)
let MCNNavDefaultItemTextColor = UIColor.black

let MCNNavDefaultTitleSize = 17.0
let MCNNavDefaultSubTItleSize = 10.0
let MCNNavDefaultItemFontSize = 15.0

let MCNNavDefaultItemSize = 22.0
let MCNNavDefaultItemMargin = 10.0

let MCNNavHistoryStackCellHeight = 44.0
let MCNNavHistoryStackCellTitleX = 16.0
let MCNNavHistoryStackViewWidth = 250.0
let MCNNavHistoryStackViewItemMaxLength = 6
let MCNNavHistoryStackViewStyleDarkBackgroundColor = UIColor(red: 16 / 255, green: 16 / 255, blue: 16 / 255, alpha: 1)
let MCNNavHistoryStackViewStyleDarkSelectedColor = UIColor(red: 66 / 255, green: 66 / 255, blue: 66 / 255, alpha: 1)
let MCNNavHistoryStackViewStyleLightBackgroundColor = UIColor(red: 255 / 255, green: 255 / 255, blue: 255 / 255, alpha: 1)
let MCNNavHistoryStackViewStyleLightSelectedColor = UIColor(red: 225 / 255, green: 225 / 255, blue: 225 / 255, alpha: 1)

let MCNMainWindow : UIWindow = UIApplication.shared.keyWindow ?? UIApplication.shared.windows.first!

/// 判断是否是pad
func MCNIsPad() -> Bool {
    return UIDevice.current.userInterfaceIdiom == .pad
}

/// 判断是否是刘海屏
func MCNIsBangScreen() -> Bool {
    var cFlag = false
    if MCNIsPad() {
        cFlag = false
    } else if #available(iOS 11.0, *) {
        if MCNMainWindow.safeAreaInsets.bottom > 0 {
            cFlag = true
        } else {
            cFlag = false
        }
    } else {
        cFlag = false
    }
    return cFlag
}

/// 是否是全面屏ipad
func MCNIsFullScreenPad() -> Bool {
    var cFlag = false
    if #available(iOS 11.0, *) {
        if MCNMainWindow.safeAreaInsets.bottom > 0 && MCNIsPad() {
            cFlag = true
        } else {
            cFlag = false
        }
    } else {
        cFlag = false
    }
    return cFlag
}

/// 判断手机是否横屏
func MCNIsHorizontalScreen() -> Bool {
    return UIApplication.shared.statusBarOrientation == .landscapeLeft || UIApplication.shared.statusBarOrientation == .landscapeRight
}

/// 屏幕宽度
let MCNScreenWidth = UIScreen.main.bounds.width
/// 屏幕高度
let MCNScreenHeight = UIScreen.main.bounds.height

/// 导航栏高度（不包含状态栏）
let MCNNavBarHeightNotIncludeStatusBar = MCNIsPad() ? 50.0 : 44.0

/// 设备状态栏高度
func MCNIPhoneAppStatusBarHeight() -> CGFloat {
    var height : CGFloat = 0
    if #available(iOS 13.0, *) {
        height = UIApplication.shared.statusBarFrame.height != 0 ? UIApplication.shared.statusBarFrame.height : (MCNIsBangScreen() ? 44.0 : 20.0)
    } else {
        height = MCNIsBangScreen() ? 44.0 : 20.0
    }
    return height
}

/// 状态栏真实高度
let MCNRealStatusBarHeight = UIApplication.shared.statusBarFrame.height

/// 状态栏高度
let MCNAppStutsBarHeight = MCNIsHorizontalScreen() ? MCNRealStatusBarHeight : MCNIsFullScreenPad() ? MCNRealStatusBarHeight : MCNIPhoneAppStatusBarHeight()

/// 导航栏高度
let MCNNavBarHeight = MCNAppStutsBarHeight + MCNNavBarHeightNotIncludeStatusBar

/// 安全区域顶部
func MCNSafeAreaTop() -> CGFloat {
    var height = CGFloat(0)
    if #available(iOS 11.0, *) {
        height = MCNMainWindow.safeAreaInsets.top
    }
    return height
}

/// 安全区域底部
func MCNSafeAreaBottom() -> CGFloat {
    var height = CGFloat(0)
    if #available(iOS 11.0, *) {
        height = MCNMainWindow.safeAreaInsets.bottom
    }
    return height
}

/// 获取横屏后左右安全距离
let MCNHorizontaledSafeArea = (MCNIsHorizontalScreen() && MCNIsBangScreen()) ? MCNNavBarHeightNotIncludeStatusBar : 0

